
use id kreis_id using "${orig_data}coordinates_kreis.dta", clear

gen bl = floor(kreis_id/1000)

gen firstday =.
	
	replace firstday = td(02Aug2021) if inlist(bl, 13, 1) // MV, SH
	replace firstday = td(05Aug2021) if bl == 2 // HH
	replace firstday = td(09Aug2021) if inlist(bl, 11, 12) //  BE, BB
	replace firstday = td(18Aug2021) if bl == 5 //NW
	replace firstday = td(30Aug2021) if inlist(bl, 6, 7, 10) // HE, RP, SL
	replace firstday = td(02Sep2021) if inlist(bl, 3, 4, 15) // NI, HB, ST
	replace firstday = td(06Sep2021) if inlist(bl, 14, 16) // SN, TH
	replace firstday = td(14Sep2021) if bl == 9 // BY
	replace firstday = td(13Sep2021) if bl == 8 // BW

format firstday %td

gen n=0

	replace n = 1 if inlist(bl, 13, 1) // MV, SH
	replace n = 2 if bl == 2 // HH
	replace n = 3 if inlist(bl, 11,12) // BE, BB
	replace n = 4 if bl == 5 //NW
	replace n = 5 if inlist(bl, 6, 7,10) // HE, RP, SL
	replace n = 6 if inlist(bl, 3, 4, 15) // NI, HB, ST
	replace n = 7 if inlist(bl, 14, 16) // SN, TH
	replace n = 8 if bl == 8 // BW
	replace n = 9 if bl == 9 // BY

	
gen open = 1

lab def openl 1 "closed" 2 "already open" 3 "open", replace
lab val open openl


local combine ""

set scheme lean2


forval o = 1/9 {
	
	replace open = 3 if n==`o'	
	replace open = 2 if n <`o' 
	
	qui sum firstday if n==`o'
	local d = r(mean)
	
	local title = string(`d', "%td")
	local title = subinstr("`title'", "aug", " August",1)
	local title = subinstr("`title'", "sep", " September",1)
	local title = subinstr("`title'", "2021", "",1)
	if strpos("`title'","0")==1 local title = subinstr("`title'", "0", "",1)
	
	spmap open using "${orig_data}shp_coord_vg250_kreis", id(id)  ///
	clm(custom) clb(0 1 2 3) fc(Greys) osize(vvthin ..) ocolor(white ..) title("`title'", size(small)) name(open_`o', replace) legend(off)
	graph export "${maps}map_`o'.png", replace
	local combine "`combine' open_`o'"

}

	replace open = 3
	spmap open using "${orig_data}shp_coord_vg250_kreis", id(id)  ///
	clm(custom) clb(0 1 2 3) fc(Blues) osize(vvthin ..) ocolor(white ..) title("All", size(vsmall)) name(open_all, replace) legend(off)
	graph export "${maps}map_all1.png", replace

	replace open = 2 if n < 6
	replace open = 3 if n >= 6
	spmap open using "${orig_data}shp_coord_vg250_kreis", id(id)  ///
	clm(custom) clb(0 1 2 3) fc(Blues) osize(vvthin ..) ocolor(white ..) title("All", size(vsmall)) name(open_all, replace) legend(off)
	graph export "${maps}map_all2.png", replace


graph combine `combine', cols(3)
graph export "${plots}map_schoolopenings.png", replace width(3000)

graph drop _all
